
package com.ifcar.app.util;

import java.util.List;
import java.util.Map;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;

import com.ifcar.app.activity.ShareToMicroBlog;
import com.ifcar.app.adapter.MicroHotAdapter;
import com.ifcar.app.rss.GetColumnsInfo;
import com.ifcar.app.activity.R;

public class MicroHotShare {
    public static void showShareDialog(final Context context, final String title2,
            final Map<String, Object> map) {
        if (map == null) {
            return;
        }
        
        new AlertDialog.Builder(context).setTitle(R.string.send_microhot).setItems(
                new String[] {
                        context.getResources().getString(R.string.resend_to_weibo),
                        context.getResources().getString(R.string.resend_to_sina),
                        context.getResources().getString(R.string.resend_to_qq),
                }, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface arg0, int arg1) {
                        // TODO Auto-generated method stub
                        Intent shareintent = new Intent(context, ShareToMicroBlog.class);
                        shareintent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        Bundle bundle = new Bundle();
                        
                        String title = StringUtil.delSpaceStr((String) map.get(GetColumnsInfo.TEXT_TAG));
                        String url = (String) map.get(GetColumnsInfo.URL_TAG);
                        
                        List<Map<String, Object>> imgList = (List<Map<String, Object>>) map.get(GetColumnsInfo.IMAGES_TAG);
        				if(null != imgList && imgList.size() > 0){
        					String imgurl = (String) imgList.get(0).get(GetColumnsInfo.SRC_TAG);
        					bundle.putString("shareimg", imgurl);
        				}
        				
        				String author = StringUtil.findMicrohotAthor(title, false);
        				if(author.contains(MicroHotAdapter.REPLAY_STRING_TAG)){
        					title = title.replaceFirst(MicroHotAdapter.REPLAY_STRING_TAG, "");
        				}
                        bundle.putString("sharetitle", title);
                        bundle.putString("shareurl", url);
                        bundle.putBoolean("microhot", true);
                        
                        switch (arg1) {
                            // 网易微博
                            case Constant.SHARE_NETEASE:
                                bundle.putInt("sharetype", 0);
                                shareintent.putExtras(bundle);
                                context.startActivity(shareintent);
                                
                                break;
                            // 新浪微博
                            case Constant.SHARE_SINA:
                                bundle.putInt("sharetype", 1);
                                shareintent.putExtras(bundle);
                                context.startActivity(shareintent);
                                
                                break;
                            // 腾讯微博
                            case Constant.SHARE_QQ:
                                bundle.putInt("sharetype", 2);
                                shareintent.putExtras(bundle);
                                context.startActivity(shareintent);
                                break;
                        }
                    }
                }).setNegativeButton("取消", null).show();
        
    }
    
}
